﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using NangLuongTieuDiemDTO.DTO;
using NangLuongTieuDiemBUS;

namespace NangLuongTieuDiemGUI.NangLuongTieuDiemForms
{
    public partial class frmLuuDuongDan : DevExpress.XtraEditors.XtraForm
    {
        public frmLuuDuongDan()
        {
            InitializeComponent();
        }

        bool isFlag = false;
        public frmLuuDuongDan(bool _isFlag)
        {
            isFlag = _isFlag;
            InitializeComponent();
        }

        #region "[tác vụ chọn ok]"
        private void btnOK_Click(object sender, EventArgs e)
        {
            try {
                if (txtPath.Text.Trim() == string.Empty)
                {
                    ClassUtils.Utils.MassageBoxErrorOtInformation("Đường dẫn không được bỏ trống","Thông báo",true);
                    return;
                }
                NangLuongTieuDiemGUI.NangLuongTieuDiemUserControl.ucDanhSachThietBiDien.m_strPathExportExcel = txtPath.Text;
                NangLuongTieuDiemGUI.NangLuongTieuDiemUserControl.ucLapHoaDonBanHang.m_strLocation = txtPath.Text;
                this.Close();
            }
            catch (Exception ex)
            {
                InSert_LoiHeThong("btnOK_Click", ex);
            }
        }
        #endregion

        #region "[đóng lại]"
        private void btnClose_Click(object sender, EventArgs e)
        {
            try {
                this.Close();
            }
            catch(Exception ex)
            {
                InSert_LoiHeThong("btnClose_Click", ex);
            }
        }
        #endregion

        private void txtPath_DoubleClick(object sender, EventArgs e)
        {
            
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "All|*.xls";
            if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = save.FileName;
            }
        }

        #region "[Hàm insert lỗi hệ thống]"
        public void InSert_LoiHeThong(string TenHam, Exception ex)
        {
            LoiHeThongDTO lhtDto = new LoiHeThongDTO();
            lhtDto.TenLoi = ex.Message.ToString();
            lhtDto.NgayTao = DateTime.Now;
            lhtDto.TenHamBiLoi = "frmLuuDuongDan_" + TenHam;
            lhtDto.SuaLoi = false;
            lhtDto.GhiChu = "";
            NangLuongTieuDiem_Management.LoiHeThong_Insert(lhtDto);
            MessageBox.Show(lhtDto.TenLoi);
        }
        #endregion 
    }
}